/* author:QinYongcheng */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using BLL;
using Common;
using Web.Extension;
using Microsoft.AspNetCore.Authorization;
using Web.Controllers;
using Web.Filter;

namespace Web.Controllers.Admin
{
    [Route("api/admin/[controller]/[action]")]
    [ApiController]
   // [Authorize("admin")]
    [QueryFilter]
    public class AreaController : MyBaseController<Area>
    {
        IAreaBll bll;
        public AreaController(IAreaBll bll)
        {
            this.bll = bll;
        }      
        // GET: api/admin/Area/List
        [HttpGet]
        public Result List([FromQuery] Dictionary<string, string> where,String excludes=null)
        {
            return Result.Success("succeed").SetData(bll.Query(where, excludes));
        }

        // GET: api/admin/Area/Get/5
        [HttpGet("{id}")]
        public Result Get([FromQuery] Dictionary<string, string> where)
        {
            return Result.Success("succeed").SetData(bll.SelectOne(where));
        }
        // POST: api/admin/Area/Add
        [HttpPost]
        public Result Add(Area o)
        {
            return ModelState.IsValid ? (bll.Add(o) ? Result.Success("添加成功") : Result.Error("添加失败")) : Result.Error("添加失败!" + ModelState.GetAllErrMsgStr(";")); ;
        }

        // Post: api/admin/Area/Update
        [HttpPost]
        public Result Update(Area o)
        {
            return ModelState.IsValid ? (bll.Update(o) ? Result.Success("修改成功").SetData(o) : Result.Error("修改失败")) : Result.Error("修改失败!" + ModelState.GetAllErrMsgStr(";")); ;
        }

        // Get: api/admin/Area/Delete/5
        [HttpGet("{id}")]
        public Result Delete([FromQuery] Dictionary<string, string> where)
        {
            return bll.Delete(where) ? Result.Success("删除成功") : Result.Error("删除失败");
        }
        // Post: api/admin/Area/BatchDelete
        [HttpPost]
        public Result BatchDelete([FromForm] Dictionary<string, string> where)
        {
            return bll.Delete(where) ? Result.Success("删除成功") : Result.Error("删除失败");
        }
    }
}
